package com.spy.material.service.impl;

import java.util.List;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.spy.common.utils.DateUtils;
import com.spy.material.dto.InventoryQueryDTO;
import com.spy.material.vo.InventoryPageVO;
import com.spy.material.vo.InventoryVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.spy.material.mapper.InventoryMapper;
import com.spy.material.domain.Inventory;
import com.spy.material.service.IInventoryService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import java.util.Arrays;
/**
 * 库存表Service业务层处理
 * 
 * @author twc
 * @date 2025-11-09
 */
@Service
public class InventoryServiceImpl extends ServiceImpl<InventoryMapper, Inventory> implements IInventoryService
{
    @Autowired
    private InventoryMapper inventoryMapper;

    /**
     * 查询库存表
     * 
     * @param id 库存表主键
     * @return 库存表
     */
    @Override
    public Inventory selectInventoryById(Long id)
    {
                return getById(id);
    }

    /**
     * 查询库存表列表
     * 
     * @param inventory 库存表
     * @return 库存表
     */
    @Override
    public List<Inventory> selectInventoryList(Inventory inventory)
    {
        return inventoryMapper.selectInventoryList(inventory);
    }

    /**
     * 新增库存表
     * 
     * @param inventory 库存表
     * @return 结果
     */
    @Override
    public int insertInventory(Inventory inventory)
    {
        inventory.setCreateTime(DateUtils.getNowDate());
                return save(inventory) ? 1 : 0;
    }

    /**
     * 修改库存表
     * 
     * @param inventory 库存表
     * @return 结果
     */
    @Override
    public int updateInventory(Inventory inventory)
    {
        inventory.setUpdateTime(DateUtils.getNowDate());
                return updateById(inventory) ? 1 : 0;
    }

    /**
     * 批量删除库存表
     * 
     * @param ids 需要删除的库存表主键
     * @return 结果
     */
    @Override
    public int deleteInventoryByIds(Long[] ids)
    {
                return removeByIds(Arrays.asList(ids)) ? 1 : 0;
    }

    /**
     * 删除库存表信息
     * 
     * @param id 库存表主键
     * @return 结果
     */
    @Override
    public int deleteInventoryById(Long id)
    {
                return removeById(id) ? 1 : 0;
    }

    @Override
    public InventoryPageVO all(InventoryQueryDTO inventoryQueryDTO) {
        PageHelper.startPage(inventoryQueryDTO.getPage(), inventoryQueryDTO.getPageSize());
        Page<InventoryVO>  page = inventoryMapper.all(inventoryQueryDTO);
        return new InventoryPageVO(page.getTotal(), page.getResult());
    }
}
